//////////////////////////////////////////////////////////////////////////////////
//
// B L I N K
//
// Copyright (C) 2016-2019 Blink Mobile Shell Project
//
// This file is part of Blink.
//
// Blink is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Blink is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Blink. If not, see <http://www.gnu.org/licenses/>.
//
// In addition, Blink is also subject to certain additional terms under
// GNU GPL version 3 section 7.
//
// You should have received a copy of these additional terms immediately
// following the terms and conditions of the GNU General Public License
// which accompanied the Blink Source Code. If not, see
// <http://www.github.com/blinksh/blink>.
//
////////////////////////////////////////////////////////////////////////////////


import XCTest

class ReceiptTests: XCTestCase {

  func testValidReceiptMigration() throws {
    continueAfterFailure = false

    let validMigrationToken = try requestTokenForMigration(receiptData: validReceipt, attachedTo: validUser)
    XCTAssertNotNil(validMigrationToken)
    XCTAssertNoThrow(try validMigrationToken.validateReceiptForMigration(attachedTo: validUser))

    XCTAssertThrowsError(try requestTokenForMigration(receiptData: validReceipt, attachedTo: "otherUser"),
      "Deny user after one exists") { error in
        if case ReceiptMigrationError.receiptExists(let err) = error {
          print(err)
        } else {
          XCTFail("Receipt already exists for user.")
        }
      }
  }

  func testInvalidReceiptMigration() throws {
    XCTAssertThrowsError(try requestTokenForMigration(receiptData: invalidReceipt, attachedTo: validUser),
      "Deny receipt that could not be validated by backend") { error in
      if case ReceiptMigrationError.invalidAppReceipt(let err) = error {
        print(err)
      } else {
        XCTFail("Receipt should not validate from backend.")
      }
    }
  }

  func requestTokenForMigration(receiptData: String, attachedTo user: String) throws -> MigrationToken {
    let tokenReceivedExpectation = expectation(description: "Token received")
    var migrationToken: MigrationToken!
    var error: Error? = nil

    var c = MigrationToken.requestTokenForMigration(receipt: receiptData, attachedTo: user)
      // In a regular application, the migration token is sent over a URL scheme,
      // decoded and validated on that side.
      .decode(type: MigrationToken.self, decoder: JSONDecoder())
      .sink(
        receiveCompletion: { completion in
          if case .failure(let err) = completion {
            error = err
          }
          tokenReceivedExpectation.fulfill()
        },
        receiveValue: { token in
          migrationToken = token
        }
      )
    wait(for: [tokenReceivedExpectation], timeout: 35)

    if let error = error {
      throw error
    }
    return migrationToken
  }

  let validUser = "test"
  let validReceipt = "MIISlQYJKoZIhvcNAQcCoIIShjCCEoICAQExCzAJBgUrDgMCGgUAMIICNgYJKoZIhvcNAQcBoIICJwSCAiMxggIfMAoCAQgCAQEEAhYAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgELAgEBBAMCAQAwCwIBDwIBAQQDAgEAMAsCARACAQEEAwIBADALAgEZAgEBBAMCAQMwDAIBCgIBAQQEFgI0KzAMAgEOAgEBBAQCAgDsMA0CAQMCAQEEBQwDMzY2MA0CAQ0CAQEEBQIDAkpUMA0CARMCAQEEBQwDMS4wMA4CAQkCAQEEBgIEUDI1NjAYAgEEAgECBBC44kxb9lyaQ1P2LWxed/WTMBsCAQACAQEEEwwRUHJvZHVjdGlvblNhbmRib3gwHAIBBQIBAQQUb5Qq7++TaywOSB6hfDVq4VLcEt4wHgIBDAIBAQQWFhQyMDIxLTExLTE2VDE2OjUwOjIwWjAeAgESAgEBBBYWFDIwMTMtMDgtMDFUMDc6MDA6MDBaMCcCAQICAQEEHwwdQ29tLkNhcmxvc0NhYmFuZXJvLkJsaW5rU2hlbGwwSwIBBwIBAQRDeoTIZ884Re47rJMZHe5J+cONc6QKJAHiuw0qhu82BfohqSFAI1co8VjG3299xfy8Y6Xl8++IZ7tkU1qiiZ1V0xo93zBgAgEGAgEBBFi19r3Cp0o2jbVZ0PUq9V4o32Xv7lgIjlVNhBhol7y3zQ6LuH+Z4GyjXFfg5y7aYO+EkbE4h7UvK6WDxyehdF5VvZryuZxiIZcAVDVy4AZAqw/4HEdljOEUoIIOZTCCBXwwggR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FwcGxlIFdvcmxkd2lkZSBEZXZlbG9wZXIgUmVsYXRpb25zMUQwQgYDVQQDDDtBcHBsZSBXb3JsZHdpZGUgRGV2ZWxvcGVyIFJlbGF0aW9ucyBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eQIIDutXh+eeCY0wCQYFKw4DAhoFADANBgkqhkiG9w0BAQEFAASCAQCJ9ctD+7Yi9JWvl6G+1HOcDO++mhY6rc6japAgogVF4xmIdh275IKRwZKpQbhoJmxXwElbMjkIsXks/48/EzuaHDQBNIVowq8qQaSUb3msvfAZfi7RGnhaJGzkXf7azr9NLMxX29R2jTiw2oaz2ri49piggmrGfXsLjWs9zTHWHHNRN1fLTPtcWb95JbQNAiQqlecG5a95/+KZ7+joh8fQwbthe8oWs5Tla0DDwrEoIbc5yjFT18Dln5bndTvWQJZcsbI4xa7BAEhjg/nfwPhaL17tHZeW8mOcCtG9UcuAgXXC6usVAOSocenhmKUR8W+D6F/jhBn0k9ahApPDmpZh"
  // TODO Test Expiration
  // TODO Test Unmatching user
  // TODO Test Invalid signature
  let expiredTokenJSON = ""

}
